import React from 'react';
import { connect } from 'react-redux';
import Flow from 'src/routers/Strategy/Strategy/flow/flow';
import useActionsData from 'src/hook/useActionsData';
import useOperatorData from 'src/hook/useOperatorData';
import ReturnVariables from 'src/routers/Strategy/Strategy/flow/returnVariables';
import { USAGE_SCOPE_LIMIT, VARIABLE_TYPE } from 'src/utils/constant';
import useVariableData from '../../../hook/useVariableData';
import Modal from 'src/components/Modal';
import { Button, Row, Col } from 'antd';

function FlowLogs(props) {
  console.log(7894, props);
  const {
    flows,
    strategy_data = {},
    variables = [],
    edge_configs = [],
    return_variables = [],
    using_variables = [],
    name,
    app_id,
    event_id,
  } = props;
  const actions = useActionsData(USAGE_SCOPE_LIMIT._STRATEGY); //获取动作函数的列表
  const operator = useOperatorData();
  const variable = useVariableData({
    limitType: [
      VARIABLE_TYPE._FIELD,
      VARIABLE_TYPE._FEATURE,
      VARIABLE_TYPE._MODEL,
      VARIABLE_TYPE._NAMELIST,
      VARIABLE_TYPE._THIRD_FEATURE,
      VARIABLE_TYPE._STRATEGY,
      VARIABLE_TYPE._RISK_LEVEL,
      VARIABLE_TYPE._LITERAL,
    ],
    appId: app_id,
    eventId: event_id,
    codes: props.codes,
  });

  const showReturnResult = () => {
    const index = Modal.open({
      title: '决策结果',
      width: '1200px',
      content: (
        <div className='stretegy-content'>
          <ReturnVariables
            {...props}
            returnResults={return_variables.map((it) => {
              const code = it.decision_set_code ? it.decision_set_code + ',' + it.code : it.code;
              const _cur = variables.find((item) => item.code === code);
              if (_cur) {
                const value = it.var_type === 'literal' ? _cur.code : _cur.value;
                it.result = typeof value === 'boolean' ? value.toString() : value;
                // it.data_type_name = _cur.data_type_name;
              }
              return it;
            })}
            codes={(props.codes && props.codes.return_variable) || []}
            value={return_variables}
            disabled={true}
            isResult={true}
          />
        </div>
      ),
      maskClosable: false,
      isOkBtn: true,
      ok: () => {
        Modal.close(index);
      },
      isCancelBtn: true,
    });
  };
  return (
    <div>
      {/* <Row type='flex' style={{ lineHeight: '3' }} gutter={100}>
        <Col>
          <div className='tantuer-form-item2'>
            <div className='ant-form-item-label'>
              <label>策略名称</label>
            </div>
            <span>{name}</span>
          </div>
        </Col>
        <Col>
          <div className='tantuer-form-item2'>
            <div className='ant-form-item-label'>
              <label>决策结果</label>
            </div>
            {return_variables.length > 0 ? (
              <Button type='link' onClick={() => showReturnResult()}>
                查看详情
              </Button>
            ) : (
              '无'
            )}
          </div>
        </Col>
      </Row> */}

      <Flow
        {...props}
        operator={operator}
        value={flows}
        disabled={true}
        graphicMode={'result'}
        isResult={true}
        flow_node_logs={strategy_data.strategyResult.nodeResults}
        variables={variables}
        using_variables={using_variables}
        actions={actions}
        edge_configs={edge_configs}
        variable={variable}
      />
    </div>
  );
}
function mapStateToProps(state) {
  return {
    codes: {
      ...state.code,
    },
  };
}
export default connect(mapStateToProps)(FlowLogs);
